package com.kaifamiao.mapper;

import com.kaifamiao.model.SelectSeatModel;
import com.kaifamiao.provider.SeatProvider;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface SeatMapper {

    @SelectProvider(value = SeatProvider.class,method = "selectOneSeat")
    List<SelectSeatModel> selectOneSeat(@Param("sno") int sno, @Param("fno")int fno, @Param("rno")String rno);

    @SelectProvider(value = SeatProvider.class,method = "selectSeat")
    List<SelectSeatModel> selectSeat(@Param("fno")int fno, @Param("rno")String rno);

    @SelectProvider(value = SeatProvider.class,method = "oKSeat")
    List<Integer> oKSeat(@Param("fno")int fno, @Param("rno")String rno);

    @Update("<script>" +
            "UPDATE seat s LEFT JOIN room r on s.rno = r.rno LEFT JOIN floor f on r.fno = f.fno SET s.sstate = 1 where s.sno = #{sno} AND f.fno = #{fno} AND r.rno = #{rno} and s.sstate = 0"
            + "</script>")
    int updateSeat (@Param("sno") int sno, @Param("fno")int fno, @Param("rno")String rno);

    //将座位状态重新置为 0
    @Update("<script>" +
            "UPDATE seat s LEFT JOIN room r on s.rno = r.rno LEFT JOIN floor f on r.fno = f.fno SET s.sstate = 0 where s.sno = #{sno} AND f.fno = #{fno} AND r.rno = #{rno} and s.sstate = 1"
            + "</script>")
    int resetSeat(@Param("sno")int sno, @Param("fno")int fno, @Param("rno")String rno);

}
